package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DisciplinaryRecord;
import com.ruoyi.system.service.IDisciplinaryRecordService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 征信档案Controller
 * 
 * @author 503
 * @date 2021-05-04
 */
@Controller
@RequestMapping("/system/record")
public class DisciplinaryRecordController extends BaseController
{
    private String prefix = "system/record";

    @Autowired
    private IDisciplinaryRecordService disciplinaryRecordService;

    @RequiresPermissions("system:record:view")
    @GetMapping()
    public String record()
    {
        return prefix + "/record";
    }

    /**
     * 查询征信档案列表
     */
    @RequiresPermissions("system:record:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DisciplinaryRecord disciplinaryRecord)
    {
        startPage();
        List<DisciplinaryRecord> list = disciplinaryRecordService.selectDisciplinaryRecordList(disciplinaryRecord);
        return getDataTable(list);
    }

    /**
     * 导出征信档案列表
     */
    @RequiresPermissions("system:record:export")
    @Log(title = "征信档案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DisciplinaryRecord disciplinaryRecord)
    {
        List<DisciplinaryRecord> list = disciplinaryRecordService.selectDisciplinaryRecordList(disciplinaryRecord);
        ExcelUtil<DisciplinaryRecord> util = new ExcelUtil<DisciplinaryRecord>(DisciplinaryRecord.class);
        return util.exportExcel(list, "征信档案数据");
    }

    /**
     * 新增征信档案
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存征信档案
     */
    @RequiresPermissions("system:record:add")
    @Log(title = "征信档案", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DisciplinaryRecord disciplinaryRecord)
    {
        return toAjax(disciplinaryRecordService.insertDisciplinaryRecord(disciplinaryRecord));
    }

    /**
     * 修改征信档案
     */
    @GetMapping("/edit/{disciplinaryId}")
    public String edit(@PathVariable("disciplinaryId") Long disciplinaryId, ModelMap mmap)
    {
        DisciplinaryRecord disciplinaryRecord = disciplinaryRecordService.selectDisciplinaryRecordById(disciplinaryId);
        mmap.put("disciplinaryRecord", disciplinaryRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存征信档案
     */
    @RequiresPermissions("system:record:edit")
    @Log(title = "征信档案", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DisciplinaryRecord disciplinaryRecord)
    {
        return toAjax(disciplinaryRecordService.updateDisciplinaryRecord(disciplinaryRecord));
    }

    /**
     * 删除征信档案
     */
    @RequiresPermissions("system:record:remove")
    @Log(title = "征信档案", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(disciplinaryRecordService.deleteDisciplinaryRecordByIds(ids));
    }
}
